using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using XKPlatform.Common;
using System;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using CacheHelper;
using XKPlatform.Common.Const;
using XKPlatform.Common.Enums;
using XKPlatform.Common.Extends;
using XKPlatform.DataModels;
using Microsoft.AspNetCore.Http;
using System.Reflection.Metadata;
using FreeSql;
using XKPlatform.DataModels.DBHelper;
using XKPlatform.DataModels.Dao.BaseDao;
using XKPlatform.DataModels.SysModel;

namespace XKPlatform.Common
{

    public partial class SSOClient
    {


        public static ICache _cache = HttpContextCore.ServiceProvider.GetService(typeof(ICache)) as ICache;

        /// <summary>
        /// 子系统获取AccessToken接口
        /// </summary>
        public const string GETACCESSTOKENAPI = "/api/Power/GetAccessToken";

        /// <summary>
        /// LoginToken转换为AccessToken接口
        /// </summary>
        public const string CONVERTTOKENAPI = "/api/Power/ConvertToken";

        /// <summary>
        /// 刷新AccessToken接口
        /// </summary>
        public const string REFRESHTOKENAPI = "/api/Power/HeartBeat";

        /// <summary>
        /// 验证Token
        /// </summary>
        public const string CHECKTOKENAPI = "/api/Power/CheckToken";

        /// <summary>
        /// 安全退出
        /// </summary>
        public const string CLEARTOKENAPI = "/api/Power/ClearToken";

        /// <summary>
        /// 记录在线时长
        /// </summary>
        public const string ONLINETIME = "onlinetime";

        public static bool IsLogin
        {
            get
            {
                //return HttpContextCore.Current != null &&
                //    HttpContextCore.Current.User != null && HttpContextCore.Current.User.Claims != null
                //    && HttpContextCore.Current.User.Claims.ToList().Find(x => x.Type == "UserData") != null
                //    && Convert.ToInt32(HttpContextCore.Current.User.Claims.ToList().Find(x => x.Type == "exp").Value) > new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();

                //if (User == null)
                //{
                //    return false;
                //}
                //else
                //{
                return true;
                // }
            }
        }
        public static bool Validate(string sign, string password, out SysUser userModel)
        {
            //sign = "develop";
            //password = "b4e4a3a4c39a0038f6f02583109183ea";//V!0o!8V@5d
            QuerySuite querySuite = new QuerySuite("SysUser a where RecordStatus=0 and (UserNo=@UserNo or Email=@UserNo or ShortNo=@UserNo) and Password=@Password Order By Org desc", "a.*");
            querySuite.AddParam("UserNo", sign);
            querySuite.AddParam("Password", password);
            var dt = SqlHelper.Query(querySuite.SelectSql, querySuite.Params) == null ? null : SqlHelper.Query(querySuite.SelectSql, querySuite.Params).Tables[0];
            if (dt == null)
            {
                userModel = null;
                return false;
            }
            userModel = ModelHelper<SysUser>.ConvertToModel(dt);
            if (userModel == null)
            {
                return false;
            }
            var role = dt.Rows[0]["DefaultRoleID"].ToString().ToUpper();
            //系统内置角色 不能修改
            if (role == "3885683D-92EC-4BF8-851C-FCD38EAA3A7B" || role == "733CE53D-83CC-4EC4-8E8C-C91C7A144805")
            {
                userModel.IsAdmin = true;

            }
            if (role == HttpContextCore.developID)
            {
                userModel.IsDev = true;
            }


            return true;
        }

        public static bool Validate(string sign, out SysUser userModel)
        {
            //sign = "develop";
            //password = "b4e4a3a4c39a0038f6f02583109183ea";//V!0o!8V@5d
            QuerySuite querySuite = new QuerySuite(@"SysUser a
  inner join SysUserRole b on b.roleId = a.DefaultRoleID where a.RecordStatus=0 and UserNo=@UserNo Order By Org desc");
            querySuite.AddParam("UserNo", sign);
            userModel = ModelHelper<SysUser>.ConvertToModel(SqlHelper.Query(querySuite.SelectSql, querySuite.Params).Tables[0]);

            if (userModel == null)
                return false;

            return true;
        }

        /// <summary>
        /// 退出清理缓存
        /// </summary>
        public static void SignOut(HttpContext ctx)
        { 
            string accessToken = _cache.GetOrDefault(RedisKeyConst.UserAccesstoken + getUser(ctx).UserID);
             
            SubsystemClearToken(accessToken, ctx); 
        }

        /// <summary>
        /// 清除认证中心AccessToken
        /// </summary>
        /// <param name="accessToken"></param>
        private static void CertificationCenterClearToken(string accessToken)
        {
            string res = HttpHelper.HttpPost1(ApiHost.TrimEnd('/') + CLEARTOKENAPI + "?strAccessToken=" + accessToken, new Dictionary<string, string>(), "");
        }

        /// <summary>
        /// 清除本地Token
        /// </summary>
        /// <param name="accessToken"></param>
        private static void SubsystemClearToken(string accessToken, HttpContext ctx)
        {
            try
            {
                string getUserAccessTokenKey = RedisKeyConst.UserAccesstoken + getUser(ctx).UserID;
                string getUserAccesstokenByUserInfoKey = RedisKeyConst.UserAccesstokenByUserInfo + accessToken;
                _cache.Remove(getUserAccessTokenKey);
                _cache.Remove(getUserAccesstokenByUserInfoKey);
            }
            catch
            {
                string sql = $"DELETE sysLoginAccessToken where AccessToken ='{accessToken}' ";
                SqlHelper.ExecuteSql(sql);
            }
        }
        /// <summary>
        /// 从上下文中获取用户信息
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>

        public static SysUser getUser(HttpContext ctx)
        {
            try
            {

                var usrJson = ctx.Request.Headers["userInfo"].ToString();
                string json = Encoding.UTF8.GetString(Convert.FromBase64String(usrJson));
                SysUser sysUser = JsonConvert.DeserializeObject<SysUser>(json);

                return sysUser;
            }
            catch (Exception ex)
            {
                return null;
            }
            //HttpContextCore.Current.User.Claims.ToList().Find(x => x.Type == "UserData")?.Value);

        }
        /// <summary>
        ///根据请求头的用户信息 序列化成用户对象
        /// </summary>
        /// <param name="usrJson"></param>
        /// <returns></returns>
        public static SysUser getUser(string usrJson)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(usrJson))
                {
                    return null;
                }
                string json = Encoding.UTF8.GetString(Convert.FromBase64String(usrJson));
                SysUser sysUser = JsonConvert.DeserializeObject<SysUser>(json);

                return sysUser;
            }
            catch (Exception ex)
            {
                return null;
            }
            //HttpContextCore.Current.User.Claims.ToList().Find(x => x.Type == "UserData")?.Value);

        } 

        //public JwtUser GetUser()
        //{
        //    var tt = HttpContextCore.Current.Request.Headers["userInfo"].ToString();
        //    string json = Encoding.UTF8.GetString(Convert.FromBase64String(HttpContextCore.Current.Request.Headers["userInfo"].ToString()));
        //    JwtUser jwtUser = JsonConvert.DeserializeObject<JwtUser>(json);
        //    return jwtUser;
        //}

        //public static Guid UserId => User == null ? Guid.Empty : User.UserID;
        //public static string UserNo => User == null ? "" : User.UserNo;
        //public static string Org => User == null ? "" : User.Org;
        //public static Guid? DepartmentID => User == null ? Guid.Empty : User.DepartmentID == null ? Guid.Empty : User.DepartmentID;
        //public static string DepartmentNo => User == null ? string.Empty : User.DepartmentNo == null ? string.Empty : User.DepartmentNo;
        //public static string Roles => User == null ? string.Empty : User.Roles;
        //public static bool IsDev => User == null ? false : User.IsDev;
        //public static bool IsAdmin => User == null ? false : User.IsAdmin;
        //public static bool IsAreaAdmin => User == null ? false : User.IsAreaAdmin;
        //public static bool IsManage => User == null ? false : User.IsManage;
        //public static int Source => User.Source != 1 ? 2 : User.Source;
        //public static string project;

        /// <summary>
        /// 中台token配置
        /// </summary>
        public static CertificationCenterConfig CertificationCenterConfig
        {
            get
            {
                string sql = "";
                DataSet dataSet = null;
                CertificationCenterConfig Certification=new CertificationCenterConfig();
                try
                {
                    if (_cache.KeyExists(RedisKeyConst.CertificationCenterConfig))
                    {
                        Certification = JsonConvert.DeserializeObject<CertificationCenterConfig>(_cache.GetOrDefault(RedisKeyConst.CertificationCenterConfig));
                        return Certification;
                    }
                }
                catch
                { 

                    return Certification;
                } 
                return Certification;
            }
        }

        /// <summary>
        /// 系统编码
        /// </summary>
        public static string SystemNum => CertificationCenterConfig?.SystemNum ?? "";
        /// <summary>
        /// 认证中心分配的Token
        /// </summary>
        public static string SYSToken => CertificationCenterConfig?.SYSToken ?? "";
        /// <summary>
        /// 认证中心host
        /// </summary>
        public static string ApiHost => CertificationCenterConfig?.ApiHost ?? "";
        /// <summary>
        ///认证中心登录页
        /// </summary>
        public static string LoginUrl => CertificationCenterConfig.LoginUrl ?? "";

        /// <summary>
        /// 登录类型 1、认证中心登录，2、中台子系统登录
        /// </summary>
        public static int LoginType => CertificationCenterConfig.LoginType;

        /// <summary>
        /// 中台登录url
        /// </summary>
        public static string MidEdnLoginUrl => CertificationCenterConfig.MidEdnLoginUrl ?? "";

        /// <summary>
        /// 认证中心登录枚举
        /// </summary>
        public static int CertificationCenter => (int)LoginTypeEnum.认证中心;

        /// <summary>
        /// 子系统登录枚举
        /// </summary>
        public static int Subsystem => (int)LoginTypeEnum.子系统;



        /// <summary>
        /// 获取AccessToken
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static string GetAccessToken(string userId, string userName, SysUser user)
        {
            AccessTokenModel resModel = null;
            string userInfo = JsonConvert.SerializeObject(user);

            try
            {
                return GetDBAccessToken(userId, userName, userInfo);
            }
            catch
            {
                resModel = GetCertificationCenterAccessToken(userId, userName, userInfo);
            }



            if (resModel == null || resModel.ErrCode != "0" || string.IsNullOrEmpty(resModel.Data?.AccessToken))
            {
                return GetDBAccessToken(userId, userName, userInfo);
            }

            return resModel.Data.AccessToken;


        }

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        private static AccessTokenModel GetCertificationCenterAccessToken(string userId, string userName, string userInfo)
        {
            GetAccessTokenRequestModel postdata = new GetAccessTokenRequestModel
            {
                Data = new List<GetAccessTokenRequestDataModel>
                    {
                        new GetAccessTokenRequestDataModel
                        {
                            SystemNum = SystemNum, SYSToken = SYSToken, UserID = userId, UserName = userName, UserInfo = userInfo
                        }
                    }
            };

            string res = HttpHelper.HttpPost2(ApiHost.TrimEnd('/') + GETACCESSTOKENAPI, new Dictionary<string, string>(), JsonConvert.SerializeObject(postdata));

            AccessTokenModel accessTokenModel = JsonConvert.DeserializeObject<AccessTokenModel>(res);

            TimeSpan timeSpan;
            string token;
            try
            {
                string getUserAccessTokenKey = RedisKeyConst.UserAccesstoken + userId;
                string getUserAccessTokenByUserInfoKey = RedisKeyConst.UserAccesstokenByUserInfo;

                if (_cache.KeyExists(getUserAccessTokenKey))
                {
                    token = _cache.GetOrDefault(getUserAccessTokenKey);
                    string key = getUserAccessTokenByUserInfoKey + token;
                    if (_cache.KeyExists(key))
                    {
                        _cache.Remove(key);
                    }
                }

                token = CalculateToken(userId, userName);
                timeSpan = TimeSpan.FromHours(GlobleConst.expTime);
                _cache.Set(getUserAccessTokenKey, token, timeSpan);
                _cache.Set(getUserAccessTokenByUserInfoKey + token, userInfo, timeSpan);
            }
            catch
            { }

            return accessTokenModel;

        }

        /// <summary>
        /// 生成token
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        private static string CalculateToken(string userId, string userName)
        {
            return EncryptHelper.MD5(userId + userName + Guid.NewGuid());
        }
        /// <summary>
        /// 强制退出用户
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static bool RemovePerson(string userId)
        {
            string getUserAccessTokenKey = RedisKeyConst.UserAccesstoken + userId;
            string getUserAccessTokenByUserInfoKey = RedisKeyConst.UserAccesstokenByUserInfo;
            string token = "";
            if (_cache.KeyExists(getUserAccessTokenKey))
            {
                token = _cache.GetOrDefault(getUserAccessTokenKey);
                string key = getUserAccessTokenByUserInfoKey + token;
                if (_cache.KeyExists(key))
                {
                    _cache.Remove(key);
                    _cache.Remove(getUserAccessTokenKey);
                }
            }
            return true;
        }

        /// <summary>
        /// 获取中台库中的token
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        private static string GetDBAccessToken(string userId, string userName, string userInfo)
        {
            string token;
            TimeSpan timeSpan;
            try
            {
                string getUserAccessTokenKey = RedisKeyConst.UserAccesstoken + userId;
                string getUserAccessTokenByUserInfoKey = RedisKeyConst.UserAccesstokenByUserInfo;

                if (_cache.KeyExists(getUserAccessTokenKey))
                {
                    token = _cache.GetOrDefault(getUserAccessTokenKey);
                    string key = getUserAccessTokenByUserInfoKey + token;
                    if (_cache.KeyExists(key))
                    {
                        _cache.Remove(key);
                        _cache.Remove(getUserAccessTokenKey);
                    }
                }

                token = CalculateToken(userId, userName);
                timeSpan = TimeSpan.FromHours(GlobleConst.expTime);
                _cache.Set(getUserAccessTokenKey, token, timeSpan);
                _cache.Set(getUserAccessTokenByUserInfoKey + token, userInfo, timeSpan);

                return token;
            }
            catch (Exception ex)
            {
                string sql = $"SELECT slat.Id,slat.AccessToken,slat.ExpireDate, slat.UserId, slat.UserInfo FROM sysLoginAccessToken slat where slat.UserId='{userId}' ";
                DataSet dataSet = SqlHelper.Query(sql);

                var datTime = DateTime.Now.AddHours(GlobleConst.expTime).ToString("yyyy-MM-dd HH:mm:ss");
                if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                {
                    token = CalculateToken(userId, userName);

                    sql = $"insert into sysLoginAccessToken (Id, AccessToken ,ExpireDate,UserId,UserInfo ) Values('{Guid.NewGuid()}','{ token}','{datTime}','{userId}','{userInfo}');";
                    SqlHelper.ExecuteSql(sql);
                    return token;
                }

                token = CalculateToken(userId, userName);

                SqlHelper.ExecuteSql($"UPDATE sysLoginAccessToken set AccessToken='{token}',ExpireDate ='{datTime}'  where UserId ='{userId}' ");

                return token;
            }

        }

        /// <summary>
        /// 验证token
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public static (bool, AccessTokenDataModel) CheckToken(string accessToken)
        {
            return SubsystemCheckToken(accessToken);

        }


        /// <summary>
        /// 认证中心CheckToken
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        private static (bool, AccessTokenDataModel) CertificationCenterCheckToken(string accessToken)
        {
            string res = HttpHelper.HttpPost1(ApiHost.TrimEnd('/') + CHECKTOKENAPI + "?strAccessToken=" + accessToken + "&SYSNum=" + SystemNum, new Dictionary<string, string>(), "");
            Console.WriteLine("CheckToken:" + res);
            AccessTokenModel getAccessTokenModel = JsonConvert.DeserializeObject<AccessTokenModel>(res);
            if (getAccessTokenModel == null && getAccessTokenModel.ErrCode != "0")
            {
                //return (false, new AccessTokenDataModel { LoginType = CertificationCenter });
                return SubsystemCheckToken(accessToken);
            }

            if (getAccessTokenModel.Data.LoginType == CertificationCenter)
            {
                dynamic userdata = new { getAccessTokenModel.Data.UserID, UserNo = getAccessTokenModel.Data.LoginAccount, UserName = getAccessTokenModel.Data.ChineseName, Org = "HFC", Roles = getAccessTokenModel.Data.RoleID };
                getAccessTokenModel.Data.UserInfo = JsonConvert.SerializeObject(userdata);
                return (true, getAccessTokenModel.Data);
            }

            if (getAccessTokenModel.Data.LoginType == Subsystem)
            {
                SysUser userModel = JsonConvert.DeserializeObject<SysUser>(getAccessTokenModel.Data.UserInfo);

                if (userModel == null)
                {
                    return (false, new AccessTokenDataModel { LoginType = Subsystem });
                }
                dynamic userdata = new { userModel.UserID, userModel.UserNo, userModel.UserName, userModel.Org, Roles = userModel.DefaultRoleID };
                getAccessTokenModel.Data.UserInfo = JsonConvert.SerializeObject(userdata);

                return (true, getAccessTokenModel.Data);
            }


            return (false, new AccessTokenDataModel { LoginType = CertificationCenter });
        }

        /// <summary>
        /// 子系统CheckToken
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        private static (bool, AccessTokenDataModel) SubsystemCheckToken(string accessToken)
        {

            try
            {
                string getUserAccesstokenByUserInfoKey = RedisKeyConst.UserAccesstokenByUserInfo + accessToken;
                if (_cache.KeyExists(getUserAccesstokenByUserInfoKey))
                {
                    string userInfo = _cache.GetOrDefault(getUserAccesstokenByUserInfoKey);
                    SysUser userModel = JsonConvert.DeserializeObject<SysUser>(userInfo);

                    if (userModel == null)
                    {
                        return CertificationCenterCheckToken(accessToken);
                    }
                    dynamic userdata = new { userModel.UserID, userModel.UserNo, userModel.UserName, userModel.Org, userModel.DefaultRoleID, project = userModel.project, IsAdmin = userModel.IsAdmin, IsDev = userModel.IsDev, DepartmentID = userModel.DepartmentID, DepartmentNo = userModel.DepartmentNo };
                    return (true, new AccessTokenDataModel { LoginType = Subsystem, UserInfo = JsonConvert.SerializeObject(userdata) });
                }

                return (false, new AccessTokenDataModel { LoginType = Subsystem });
            }
            catch
            {
                string sql = $"SELECT slat.Id,slat.AccessToken,slat.ExpireDate, slat.UserId,slat.UserInfo FROM sysLoginAccessToken slat where slat.AccessToken='{accessToken}' ";
                DataSet dataSet = SqlHelper.Query(sql);

                if (dataSet == null || dataSet.Tables[0] == null || dataSet.Tables[0].Rows.Count == 0)
                {
                    return (false, new AccessTokenDataModel { LoginType = Subsystem });
                }

                if (Convert.ToDateTime(dataSet.Tables[0].Rows[0]["ExpireDate"]) < DateTime.Now)
                {
                    return (false, new AccessTokenDataModel { LoginType = Subsystem });
                }

                string userInfo = dataSet.Tables[0].Rows[0]["UserInfo"].ToString();

                SysUser userModel = JsonConvert.DeserializeObject<SysUser>(userInfo);

                if (userModel == null)
                {
                    return CertificationCenterCheckToken(accessToken);
                }
                dynamic userdata = new { userModel.UserID, userModel.UserNo, userModel.UserName, userModel.Org, userModel.DefaultRoleID, project = userModel.project, IsAdmin = userModel.IsAdmin, IsDev = userModel.IsDev, DepartmentID = userModel.DepartmentID, DepartmentNo = userModel.DepartmentNo };
                return (true, new AccessTokenDataModel { LoginType = Subsystem, UserInfo = JsonConvert.SerializeObject(userdata) });
            }


        }

        /// <summary>
        /// 根据loginToken转换AccessToken
        /// </summary>
        /// <param name="loginToken"></param>
        /// <returns></returns>
        public static string ConvertToken(string loginToken)
        {
            string res = HttpHelper.HttpPost1(ApiHost.TrimEnd('/') + CONVERTTOKENAPI + "?strLoginToken=" + loginToken, new Dictionary<string, string>(), "");
            AccessTokenModel getAccessTokenModel = JsonConvert.DeserializeObject<AccessTokenModel>(res);
            if (getAccessTokenModel != null && getAccessTokenModel.ErrCode == "0")
            {
                string accessToken = getAccessTokenModel.Data?.AccessToken;
                return accessToken ?? "";
            }

            return "";
        }

        public static string GetSkipUrl(string proId)
        {
            try
            {
                string getSkipUrlKey = RedisKeyConst.SkipUrl + proId;
                if (_cache.KeyExists(getSkipUrlKey))
                {
                    return _cache.GetOrDefault(getSkipUrlKey);
                }

                string sql = $"select  proUrl from [dbo].[SysProject] where ProjectNo='{proId}' ";
                var proUrl = SqlHelper.GetSingle(sql);

                if (proUrl == null)
                {
                    return "";
                }

                _cache.Set(getSkipUrlKey, proUrl.ToString());

                return proUrl.ToString();
            }
            catch
            {
                string sql = $"select  proUrl from [dbo].[SysProject] where ProjectNo='{proId}' ";
                var proUrl = SqlHelper.GetSingle(sql);

                if (proUrl == null)
                {
                    return "";
                }

                return proUrl.ToString();
            }
        } 
        
        /// <summary>
        /// 刷新accessToken
        /// </summary>
        /// <param name="accessToken"></param>
        public static void RefreshToken(int loginType, string accessToken, HttpContext ctx)
        {
            var usrJson = ctx.Request.Headers["userInfo"].ToString();
            //Console.WriteLine("RefreshToken:====" + usrJson);

            Task.Run(() =>
            {
                try
                {
                    string res = HttpHelper.HttpPost1(ApiHost.TrimEnd('/') + REFRESHTOKENAPI + "?strAccessToken=" + accessToken, new Dictionary<string, string>(), "");
                }
                catch (Exception w)
                {

                }

                try
                {
                    //Console.WriteLine("RefreshToken11:====" + usrJson);
                    var usr = getUser(usrJson);
                    string getUserAccessTokenKey = RedisKeyConst.UserAccesstoken + usr.UserID;
                    string getUserAccesstokenByUserInfoKey = RedisKeyConst.UserAccesstokenByUserInfo + accessToken;
                    TimeSpan timeSpan = TimeSpan.FromHours(GlobleConst.expTime);
                    _cache.KeyExpire(getUserAccessTokenKey, timeSpan);
                    _cache.KeyExpire(getUserAccesstokenByUserInfoKey, timeSpan);

                    //刷新在线人数 

                    //RefeshOnlineUser(usr.UserID.ToString(), usr);

                }
                catch
                {
                    SqlHelper.ExecuteSql($"UPDATE sysLoginAccessToken set ExpireDate ='{DateTime.Now.AddHours(GlobleConst.expTime)}'  where AccessToken ='{accessToken}' ");
                }

            });
        }
    }


    public class GetAccessTokenRequestModel
    {
        public IList<GetAccessTokenRequestDataModel> Data { get; set; }
    }

    public class GetAccessTokenRequestDataModel
    {
        public string SystemNum { get; set; }
        public string SYSToken { get; set; }
        public string UserID { get; set; }
        public string UserName { get; set; }
        public string UserInfo { get; set; }
    }

    public class CertificationCenterConfig
    {
        public string SystemNum { get; set; }

        public string SYSToken { get; set; }

        public string ApiHost { get; set; }

        public string LoginUrl { get; set; }

        public int LoginType { get; set; }

        public string MidEdnLoginUrl { get; set; }
    }

    public class AccessTokenModel
    {
        public string ErrCode { get; set; }

        public string Message { get; set; }

        public AccessTokenDataModel Data { get; set; }
    }

    public class AccessTokenDataModel
    {
        public string AccessToken { get; set; }

        public string UserID { get; set; }

        public string LoginAccount { get; set; }

        public string Email { get; set; }

        public string ChineseName { get; set; }

        public string TelPhone { get; set; }

        public string ExpiryTime { get; set; }

        public string UserInfo { get; set; }

        /// <summary>
        /// 登录类型 1 认证中心登录 2 子系统登录
        /// </summary>
        public int LoginType { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string RoleID { get; set; }
    }

    public class JwtUser
    {
        public Guid UserID { set; get; }
        public string UserNo { set; get; }
        public string UserName { set; get; }
        public string UserName_EN { set; get; }
        public string Email { set; get; }
        public string Mobile { set; get; }
        public string QywxUserId { set; get; }
        public string OpenID { set; get; }
        public string Org { set; get; }
        public Guid? DepartmentID { set; get; }
        public string DepartmentNo { set; get; }
        public string Roles { set; get; }
        public bool IsDev { set; get; }
        public bool IsAdmin { set; get; }
        public bool IsAreaAdmin { set; get; }
        public bool IsManage { set; get; }
        public int Source { set; get; }
        public string project { get; set; }
    }

}